package cate.game.activity.hangdrop.msg;

import cate.game.GameBody;
import cate.game.activity.hangdrop.HangDropActivity;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBHangDropActivity;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@ClientMsg(title = "限时兑换活动-兑换奖励 请求")
public class HangDropActivityExchangeReq implements MsgInput {
    @NoteField("功能ID")
    public int funcId;
    @NoteField("配置ID")
    public int tid;
    @NoteField("数量")
    public int num;

    @Override
    public MsgConfig conf() {
        return MsgIdBHangDropActivity.HANG_DROP_ACTIVITY_EXCHANGE_REQ;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        HangDropActivity single = cc.getRole().getActivity().getEnableActivitySingle(funcId);
        if (single == null) {
            cc.getRole().getGame().notice.message(cc.getRole(), "活动未开启");
            return;
        }
        EcResult<HangDropActivity> r = single.doExchange(tid, num);
        if (!r.ok()) {
            game.notice.message(cc.getRole(), r.message);
        } else {
            r.data.noticeUpdate();
        }
    }
}
